package com.dataflow.example.util;

import cn.hutool.crypto.digest.MD5;

import java.nio.charset.StandardCharsets;

/**
 * @author dx
 * @since 2022/4/2
 **/
public class Md5Util {
    private static final InheritableThreadLocal<MD5> THREAD_LOCAL = new InheritableThreadLocal<>();

    private Md5Util() {
    }

    public static String md5(String str) {
        MD5 md5 = THREAD_LOCAL.get();
        if (md5 == null) {
            md5 = MD5.create();
            THREAD_LOCAL.set(md5);
        }
        return md5.digestHex(str, StandardCharsets.UTF_8);
    }
}
